﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;

namespace rock.DAL
{
	/// <summary>
	/// 数据访问类:DalHOUSE_THING
	/// </summary>
	public partial class DalHOUSE_THING
	{
		public DalHOUSE_THING()
		{}
		#region  Method

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
		return DbHelperSQL.GetMaxID("SEQID", "HOUSE_THING"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int SEQID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from HOUSE_THING");
			strSql.Append(" where SEQID=@SEQID");
			SqlParameter[] parameters = {
					new SqlParameter("@SEQID", SqlDbType.Int,4)
			};
			parameters[0].Value = SEQID;

			return DbHelperSQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int Add(rock.Model.ModelHOUSE_THING model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into HOUSE_THING(");
            strSql.Append("ROOM_SEQID,NAME,SIZE,COUNT,PRICE,TOTLE_PRICE,NOTE)");
			strSql.Append(" values (");
            strSql.Append("@ROOM_SEQID,@NAME,@SIZE,@COUNT,@PRICE,@TOTLE_PRICE,@NOTE)");
			strSql.Append(";select @@IDENTITY");
			SqlParameter[] parameters = {
                    new SqlParameter("@ROOM_SEQID", SqlDbType.Int,4),
					new SqlParameter("@NAME", SqlDbType.VarChar,100),
					new SqlParameter("@SIZE", SqlDbType.VarChar,100),
					new SqlParameter("@COUNT", SqlDbType.Int,4),
					new SqlParameter("@PRICE", SqlDbType.Decimal,5),
					new SqlParameter("@TOTLE_PRICE", SqlDbType.Decimal,5),
					new SqlParameter("@NOTE", SqlDbType.VarChar,300)};
            parameters[0].Value = model.ROOM_SEQID;
			parameters[1].Value = model.NAME;
			parameters[2].Value = model.SIZE;
			parameters[3].Value = model.COUNT;
			parameters[4].Value = model.PRICE;
			parameters[5].Value = model.TOTLE_PRICE;
			parameters[6].Value = model.NOTE;

			object obj = DbHelperSQL.GetSingle(strSql.ToString(),parameters);
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(rock.Model.ModelHOUSE_THING model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update HOUSE_THING set ");
			strSql.Append("NAME=@NAME,");
			strSql.Append("SIZE=@SIZE,");
			strSql.Append("COUNT=@COUNT,");
			strSql.Append("PRICE=@PRICE,");
			strSql.Append("TOTLE_PRICE=@TOTLE_PRICE,");
			strSql.Append("NOTE=@NOTE");
            strSql.Append(" where SEQID=@SEQID AND ROOM_SEQID = @ROOM_SEQID");
			SqlParameter[] parameters = {
					new SqlParameter("@NAME", SqlDbType.VarChar,100),
					new SqlParameter("@SIZE", SqlDbType.VarChar,100),
					new SqlParameter("@COUNT", SqlDbType.Int,4),
					new SqlParameter("@PRICE", SqlDbType.Decimal,5),
					new SqlParameter("@TOTLE_PRICE", SqlDbType.Decimal,5),
					new SqlParameter("@NOTE", SqlDbType.VarChar,300),
					new SqlParameter("@SEQID", SqlDbType.Int,4),
                    new SqlParameter("@ROOM_SEQID", SqlDbType.Int,4)};
			parameters[0].Value = model.NAME;
			parameters[1].Value = model.SIZE;
			parameters[2].Value = model.COUNT;
			parameters[3].Value = model.PRICE;
			parameters[4].Value = model.TOTLE_PRICE;
			parameters[5].Value = model.NOTE;
			parameters[6].Value = model.SEQID;
            parameters[7].Value = model.ROOM_SEQID;
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int SEQID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from HOUSE_THING ");
			strSql.Append(" where SEQID=@SEQID");
			SqlParameter[] parameters = {
					new SqlParameter("@SEQID", SqlDbType.Int,4)
			};
			parameters[0].Value = SEQID;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string SEQIDlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from HOUSE_THING ");
			strSql.Append(" where SEQID in ("+SEQIDlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public rock.Model.ModelHOUSE_THING GetModel(int SEQID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 SEQID,ROOM_SEQID,NAME,SIZE,COUNT,PRICE,TOTLE_PRICE,NOTE from HOUSE_THING ");
			strSql.Append(" where SEQID=@SEQID");
			SqlParameter[] parameters = {
					new SqlParameter("@SEQID", SqlDbType.Int,4)
			};
			parameters[0].Value = SEQID;

			rock.Model.ModelHOUSE_THING model=new rock.Model.ModelHOUSE_THING();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["SEQID"]!=null && ds.Tables[0].Rows[0]["SEQID"].ToString()!="")
				{
					model.SEQID=int.Parse(ds.Tables[0].Rows[0]["SEQID"].ToString());
				}
                if (ds.Tables[0].Rows[0]["ROOM_SEQID"] != null && ds.Tables[0].Rows[0]["ROOM_SEQID"].ToString() != "")
                {
                    model.ROOM_SEQID = int.Parse(ds.Tables[0].Rows[0]["ROOM_SEQID"].ToString());
                }
				if(ds.Tables[0].Rows[0]["NAME"]!=null && ds.Tables[0].Rows[0]["NAME"].ToString()!="")
				{
					model.NAME=ds.Tables[0].Rows[0]["NAME"].ToString();
				}
				if(ds.Tables[0].Rows[0]["SIZE"]!=null && ds.Tables[0].Rows[0]["SIZE"].ToString()!="")
				{
					model.SIZE=ds.Tables[0].Rows[0]["SIZE"].ToString();
				}
				if(ds.Tables[0].Rows[0]["COUNT"]!=null && ds.Tables[0].Rows[0]["COUNT"].ToString()!="")
				{
					model.COUNT=int.Parse(ds.Tables[0].Rows[0]["COUNT"].ToString());
				}
				if(ds.Tables[0].Rows[0]["PRICE"]!=null && ds.Tables[0].Rows[0]["PRICE"].ToString()!="")
				{
					model.PRICE=decimal.Parse(ds.Tables[0].Rows[0]["PRICE"].ToString());
				}
				if(ds.Tables[0].Rows[0]["TOTLE_PRICE"]!=null && ds.Tables[0].Rows[0]["TOTLE_PRICE"].ToString()!="")
				{
					model.TOTLE_PRICE=decimal.Parse(ds.Tables[0].Rows[0]["TOTLE_PRICE"].ToString());
				}
				if(ds.Tables[0].Rows[0]["NOTE"]!=null && ds.Tables[0].Rows[0]["NOTE"].ToString()!="")
				{
					model.NOTE=ds.Tables[0].Rows[0]["NOTE"].ToString();
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
            strSql.Append("select SEQID,ROOM_SEQID,NAME,SIZE,COUNT,PRICE,TOTLE_PRICE,NOTE ");
			strSql.Append(" FROM HOUSE_THING ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
            strSql.Append(" SEQID,ROOM_SEQID,NAME,SIZE,COUNT,PRICE,TOTLE_PRICE,NOTE ");
			strSql.Append(" FROM HOUSE_THING ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}
 

		 

		#endregion  Method
	}
}

